package it.xiuxian.lib.utils

import android.app.Application
import android.util.Log
import com.bytedance.pangrowth.dpsdk.DPCallback
import com.bytedance.sdk.dp.DPLuck
import com.bytedance.sdk.dp.DPSdk
import com.bytedance.sdk.dp.DPSdkConfig


/**
 * @author zhouhaoyang
 * @since 6/7/21
 */
object MediaInitHelper{
    const val TAG = "MediaInitHelper"
    var isDPInited = false
    fun init(application: Application) {
        initDp(application)
    }

    fun initDp(application: Application) {
        //1. 初始化，最好放到application.onCreate()执行
        //2. 【重要】如果needInitAppLog=false，请确保AppLog初始化一定要在合作sdk初始化前
        val configBuilder = DPSdkConfig.Builder()
            .debug(false)
            .needInitAppLog(false)
            .initListener { isSuccess -> //注意：1如果您的初始化没有放到application，请确保使用时初始化已经成功
                //     2如果您的初始化在application
                //isSuccess=true表示初始化成功
                //初始化失败，可以再次调用初始化接口（建议最多不要超过3次)
                isDPInited = isSuccess
               // Log.e(TAG, "init result=$isSuccess")
                if (RuntimeUtils.containsLuckyCat()) {
                    DPLuck.callback(DPCallback.instance)
                    DPLuck.drawListener(DPCallback.instance)
                    DPLuck.gridListener(DPCallback.instance)
                    DPLuck.newsListener(DPCallback.instance)
                }
            } //接入了红包功能需要传入的参数，没有接入的话可以忽略该配置
//        val luckyCatConfig =  DPSdkConfig.LuckConfig()
//            .application(application)
//            .licenseStr("Zre23q+ugBYuAhUA9t7cvzlRXgvrb2rm9jMuQGbXL+n4FHJZj9c2I4WX7xeEG56e29+eCrq77ugnvuLkkS3340GhDVhagMQqLnefsGNKyHIY2k1g9Qpy1J0joc8eOvG0CCo+29LwqmRp5RYVZ7uki99/i3pMCeUiElgqgJwurNS6dSQ90oZkkjpNp9k9dfP0D8HZMGpNkGTVjwknS1NqQLYAnfUbGMJK+WOuk1ZFi2AYIEWBcKxaJnyyvMkq3OgezDMOcjXcbrjQzKWS8vRz9u0yIEvYrhaepa+KWTtR9TB3iO41")
//            .luckKey("WuzlrGM95YOGlCmKm32l6youdsG/zE2y")
//            .adCodeIdBox("946062125")
//            .adCodeIdMoney("946062126")
//            .adCodeIdSignIn("946062128")
//            .loginCallback {
//
//            }
        configBuilder.luckConfig(DPSdkConfig.LuckConfig().application(application).enableLuck(false))
       /* val liveConfig = com.pangrowth.business.live.LiveServiceImpl.Companion.instance.getLiveConfig() as? LiveConfig
//        if (DebugInfo.Bridge.onlylive()) {
//            liveConfig.onlyLive()
//        }
        liveConfig?.let { configBuilder.liveConfig(it) }*/

        DPSdk.init(application, "SDK_Setting_5255152.json", configBuilder.build())
    }
}